<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>客户列表</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<script type="text/javascript">
    var grid = null;
    var cstRlFlag = '${cstRlFlag}';
    $(function () {
        initForm();
        setCstClTypCd();
        initGrid();//注意初始化要在initForm之后,因为在初始化grid的时候需要form参数
        searchBtnEvent();
        clearBtnEvent();
    });
    //选择担保人时，设置客户属性不可选
    function setCstClTypCd() {
        var cstRlFlag = '${cstRlFlag}';
        var cstTypCd = ProjectConstant.CST_RL_SPONSOR;
        if (cstRlFlag == cstTypCd) {
            /* 	 var slt=liger.get("cstRlTyp");
             slt.setDisabled();
             slt.setValue(cstTypCd); */
            $("#cstTypCd").val(cstTypCd);

        }
        var cstTypCd = '${cstTypCd}';
        $("#cstTypCd").val(cstTypCd);
    }

    //清空按钮事件
    function clearBtnEvent() {
        $("#clearBtn").click(function (event) {
            $("#resetBtn").click();  //重置 input-text
            var form = liger.get("searchBar");
            form.setData({  //重置select等特殊表单
                "cstTypCd": " ",
                "cstNm": " "
                //  "cstRlTyp":" ",
            });
        });
    }

    //初始化表单
    function initForm() {
        $("#searchBar").ligerForm();
    }

    //查询按钮事件
    function searchBtnEvent() {
        $("#searchBtn").click(function (event) {
            var form = new liger.get("searchBar");
            var data = form.getData();
            data["crtTm"] = $("#crtTm").val();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            ;
            grid.reload();
        });
    }

    //查询参数
    function getSearchParams() {
        var form = new liger.get("searchBar");
        var data = form.getData();
        data["cstRlTyp"] = '${cstRlFlag}';
        var cstTypCd = '${cstTypCd}';
        if (cstTypCd) {
            data["cstTypCd"] = cstTypCd;
        }
        return data;
    }

    //初始化列表
    function initGrid() {
        var str1 = "";
        var str2 = "";
        if (cstRlFlag == ProjectConstant.CST_RL_CST) {
            str1 = "客户名称";
            str2 = "客户类型";
        }
        if (cstRlFlag == ProjectConstant.CST_RL_SPONSOR) {
            str1 = "担保人名称";
            str2 = "担保人类型";
        }
        $("#ligergrid1").ligerGrid({
            url: '<%=path%>/customer/cstbscinfo/initList.do',
            method: 'get',
            parms: getSearchParams(),
            columns: [
                /*      { display: '客户性质', name: 'cstStsCdNm', minWidth: 60, enabledSort:true },
                 { display: '客户级别', name: 'cstLvlCdNm', minWidth: 60 , enabledSort:true}, */
                {display: str1, name: 'cstNm', minWidth: 100, enabledSort: true},
                {display: str2, name: 'cstTypCdNm', width: 60, enabledSort: true},
                {display: '证件/组织机构代码', name: 'certNo', minWidth: 200, enabledSort: true},
                {
                    display: '操作',
                    isSort: false,
                    width: 100,
                    render: function (rowdata, rowindex, value) {
                        var h = '<a class="sq-button-hasicon" href="javascript:chooseCstRow(';
                        h += "'" + rowdata.id + "',";
                        h += "'" + rowdata.cstTypCd + "',";
                        h += "'" + rowdata.cstNm + "',";
                        h += ')"><i class="sqBtnIco_3"></i>选择</a>'
                        return h;
                    }
                }
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: false,
            rownumbers: true
        });
        grid = liger.get("ligergrid1");
        grid.setHeight(100);
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }


    function clearBtn() {
        var form = new liger.get("searchBar");
        form.clear();
    }

    function iframeResize() {
        if (parent.mainApp) {
            parent.mainApp.parentTab.onResize();
        }
        ;
    }
    function chooseCstRow(id, cstTypCd, name) {
        // 校验用户征信是否合规
        var url = '<%=path%>/project/prjbscinfo/queryCstCreditiInvest.do';
        var prjTypCd = $('#prjTypCd', parent.document).val();
        var params = {};
        params.cstId = id;
        //项目类型
        params.prjTypCd = prjTypCd;
        var flag = false;
        if(cstTypCd && id){
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: params,
                async : false,
                url: url,
                success: function (msg) {
                    if (msg.success == 1) {
                        if (msg.data.rcCstBscInfoMap && msg.data.rcCstBscInfoMap.rcCstBscInfoList){
                            var checkFlag = false;
                            for (var i=0;i<msg.data.rcCstBscInfoMap.rcCstBscInfoList.length;i++){
                                if (msg.data.rcCstBscInfoMap.rcCstBscInfoList[i].rskLvlCd != 3){
                                    checkFlag = true;
                                    break;
                                }
                            }
                            if(checkFlag){
                                var selectid= parent.$("#isBigCstWork").ligerGetComboBoxManager();
                                if(msg.signature && msg.signature == 1){
                                    parent.$("#isBigCstWorkDiv").show();
                                    selectid.setValue(1);
                                    selectid.setText("是");
                                }else{
                                    parent.$("#isBigCstWorkDiv").hide();
                                    selectid.setValue(0);
                                    selectid.setText("否");
                                }
                            }else{
                                parent.window.document.getElementById("cstId").value = '';
                                parent.window.document.getElementById("cstTypCd").value = '';
                                parent.window.document.getElementById("cstNm").value = '';
                                top.$.ligerDialog.SQalert({content: "当前客户无征信或征信不合规，请核实", SQ_type: "warning"});
                                return false ;
                            }
                            flag = true ;
                        }else{
                            parent.window.document.getElementById("cstId").value = '';
                            parent.window.document.getElementById("cstTypCd").value = '';
                            parent.window.document.getElementById("cstNm").value = '';
                            top.$.ligerDialog.SQalert({content: "当前客户无征信或征信不合规，请核实", SQ_type: "warning"});
                            return false ;
                        }
                    }else if(msg.success == 0){
                        parent.window.document.getElementById("cstId").value = '';
                        parent.window.document.getElementById("cstTypCd").value = '';
                        parent.window.document.getElementById("cstNm").value = '';
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "warning"});
                        return false ;
                    }else {
                        parent.window.document.getElementById("cstId").value = '';
                        parent.window.document.getElementById("cstTypCd").value = '';
                        parent.window.document.getElementById("cstNm").value = '';
                        top.$.ligerDialog.SQalert({content:"查询征信失败,请重试", SQ_type: "warning"});
                        return false ;
                    }
                }
            });
        }else{
            top.$.ligerDialog.SQalert({content: "当前客户无征信或征信不合规，请核实", SQ_type: "warning"});
        }
        if(flag){
            parent.window.document.getElementById("cstId").value = id;
            parent.window.document.getElementById("cstTypCd").value = cstTypCd;
            parent.window.document.getElementById("cstNm").value = name;
        }
        frameElement.dialog.close();
    }
</script>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">客户名称</div>
                    <div class="field">
                        <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">客户类型</div>
                    <div class="field">
                        <select name="cstTypCd" id="cstTypCd">
                            <option value=" " seleted>请选择</option>
                            <c:forEach items="${searchSelectCsttypcdlist }" var="csttypcd">
                                <option value="${csttypcd.key }">${csttypcd.value }</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <%--      <div class="fieldBox">
                         <div class="label">客户属性</div>
                         <div class="field">
                             <select name="cstRlTyp" id="cstRlTyp">
                                <option value=" ">请选择</option>
                                <c:forEach items="${cstRlTypCdList }" var="cstRlcd">
                                        <c:if test="${currentCstRlType == cstRlcd.key }">
                                            <option value="${cstRlcd.key }" selected>${cstRlcd.value }</option>
                                        </c:if>
                                     <c:if test="${currentCstRlType != cstRlcd.key }">
                                            <option value="${cstRlcd.key }">${cstRlcd.value }</option>
                                        </c:if>
                                </c:forEach>
                             </select>
                         </div>
                     </div> --%>
                <%--  <div class="fieldBox">
                     <div class="label">所属机构</div>
                     <div class="field">
                         <select name="buOrgCd" id="buOrgCd">
                             <option value=" " seleted>请选择</option>
                             <c:forEach items="${orgListList }" var="org">
                                 <c:if test="${currentBuOrgCd == org.key }">
                                     <option value="${org.key }" selected>${org.value }</option>
                                 </c:if>
                                 <c:if test="${currentBuOrgCd != org.key }">
                                     <option value="${org.key }">${org.value }</option>
                                 </c:if>
                             </c:forEach>
                         </select>
                     </div>
                 </div> --%>
                <div class="clearFix"></div>
                <div class="btnsBox">
                    <span id="searchBtn" class="sq-button sq-button-round"><!-- <i class="sqBtnIco_1"></i> -->查询</span>
                    <span id="clearBtn" class="sq-button sq-button-round"><!-- <i class="sqBtnIco_19"></i> -->清空</span>
                </div>
            </div>
        </form>
    </div>
</div>
<div id="ligergrid1" class="sq-grid"></div>
</div>
</body>
</html>